package br.com.notepadeti.model.data;

import br.com.notepadeti.model.NotaVO;
import br.com.notepadeti.util.HibernateUtil;


import org.hibernate.Session;
import org.hibernate.Transaction;

public class NotaPersistence {
    //private static Logger LOGGER = Logger.getLogger(NotaPersistence.class);
	
	
	public Boolean inserirNota(NotaVO nota) {
		Session s = HibernateUtil.getSession();
		try {
			Transaction t = s.beginTransaction();
			s.save(nota);
			t.commit();
			return true;
		} catch (Exception e) {
			//LOGGER.fatal("Falha ao atualizar Nota. " + e.getMessage());
			e.printStackTrace();
		} finally {
			s.close();
		}
		return false;
		
	}

	public Boolean atualizarNota(NotaVO nota){
		Session s = HibernateUtil.getSession();
		
		try {
			Transaction t = s.beginTransaction();			
			s.saveOrUpdate(nota);
			t.commit();
			return true;
		} catch (Exception e) {
			//LOGGER.fatal("Falha ao atualizar Nota. " + e.getMessage());
			e.printStackTrace();
		} finally {
			s.close();
		}
		return false;		
	}

	public NotaVO consultarNota(String url) {
		Session s = HibernateUtil.getSession();
		try {
			return (NotaVO) s.get(NotaVO.class, "abc");
		} catch (Exception e) {
			//LOGGER.fatal("Falha ao consultar Nota. " + e.getMessage());
			e.printStackTrace();
		} finally {
			s.close();
		}
		return null;
	}
}
